package com.yonglian.management.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * A ProjectType.
 */
@Entity
@Table(name = "project_type")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class ProjectType implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @NotNull
    @Size(min = 2, max = 50)
    @Column(name = "type_name", length = 50, nullable = false)
    private String typeName;

    @Column(name = "remark")
    private String remark;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "projectType")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(value = { "activities", "projectType" }, allowSetters = true)
    private Set<ProjectBaseInfo> projects = new HashSet<>();

    // jhipster-needle-entity-add-field - JHipster will add fields here

    public Long getId() {
        return this.id;
    }

    public ProjectType id(Long id) {
        this.setId(id);
        return this;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTypeName() {
        return this.typeName;
    }

    public ProjectType typeName(String typeName) {
        this.setTypeName(typeName);
        return this;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getRemark() {
        return this.remark;
    }

    public ProjectType remark(String remark) {
        this.setRemark(remark);
        return this;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Set<ProjectBaseInfo> getProjects() {
        return this.projects;
    }

    public void setProjects(Set<ProjectBaseInfo> projectBaseInfos) {
        if (this.projects != null) {
            this.projects.forEach(i -> i.setProjectType(null));
        }
        if (projectBaseInfos != null) {
            projectBaseInfos.forEach(i -> i.setProjectType(this));
        }
        this.projects = projectBaseInfos;
    }

    public ProjectType projects(Set<ProjectBaseInfo> projectBaseInfos) {
        this.setProjects(projectBaseInfos);
        return this;
    }

    public ProjectType addProject(ProjectBaseInfo projectBaseInfo) {
        this.projects.add(projectBaseInfo);
        projectBaseInfo.setProjectType(this);
        return this;
    }

    public ProjectType removeProject(ProjectBaseInfo projectBaseInfo) {
        this.projects.remove(projectBaseInfo);
        projectBaseInfo.setProjectType(null);
        return this;
    }

    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ProjectType)) {
            return false;
        }
        return getId() != null && getId().equals(((ProjectType) o).getId());
    }

    @Override
    public int hashCode() {
        // see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
        return getClass().hashCode();
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "ProjectType{" +
            "id=" + getId() +
            ", typeName='" + getTypeName() + "'" +
            ", remark='" + getRemark() + "'" +
            "}";
    }
}
